<!DOCTYPE html>
<html lang="en" style="background:#fff;">
<head>
<base href="${basePath}">
	 <#include "common/top.html"/>
	<link type="text/css" rel="stylesheet" href="${basePath}plugins/zTree/3.5.1/zTreeStyle/zTreeStyle.css"/>
	<script type="text/javascript" src="${basePath}plugins/zTree/3.5.1/jquery.ztree.core.js"></script>
	<script type="text/javascript" src="${basePath}plugins/zTree/3.5.1/jquery.ztree.excheck.js"></script>
</head>
<body class="layeropenbody">
	<form class="layui-form" modelAttribute="dept" name="form1" id="form1"  method="post">
		<div class="layui-form-item-dept">
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>部门编号：</label>
			<div class="layui-input-inline">
				<input class="layui-input" type="text" name="deptId" maxlength="120" id="deptId" placeholder="这里输入部门编号" value="${dept.deptId}"  title="部门编号"/>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>部门名称：</label>
			<div class="layui-input-inline">
			<input class="layui-input" type="text" name="deptName" maxlength="120" id="deptName" placeholder="这里输入部门名称" value="${dept.deptName}"  title="部门名称"/>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">上级部门：</label>
			<div class="layui-input-inline">
				<input class="layui-input" type="hidden" name="parentId" id="parentId" placeholder="上级部门" value="${dept.parentId}"  title="上级部门"/>
				<input class="layui-input" type="text" readonly name="parentName" id="parentName" placeholder="上级部门" value="${dept.parentName}"  title="上级部门"/>
				<div id="parentDiv" class="layui-elem-field" style="height: 200px;overflow: auto;">
					<ul id="tree" class="ztree" style="padding: 5px;"></ul>
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">备注：</label>
			<div class="layui-input-inline">
				<input class="layui-input" maxlength="200" type="text" name="remarks" id="remarks" placeholder="这里输入备注" value="${dept.remarks}"  title="备注"/>
			</div>
		</div>
		</div>
	</form>
</body>
<script type="text/javascript">
	var zTree;
	$(document).ready(function(){
		var id =parseInt($("#deptId").val());
		if(!isNaN(id)){
			$("#deptId").attr("readonly",true );
		}
		$("#parentDiv").hide();
		$("#parentName").click(function(event){
			$("#parentDiv").show();
			event.stopPropagation();//阻止冒泡

		});
		$("body").click(function(){
			$("#parentDiv").hide();
		})
		$('#parentDiv').click(function(){
			return false;
		});
		var zn = '${zTreeNodes}';
		var setting = {
			data: {
				key: {
					title: "dept"
				},
				simpleData: {
					enable: true,
					idKey: "id",
					pIdKey: "pId",
					rootPId: 0
				}
			},
			callback:{
				onClick: zTreeOnClick
			}
		};
		var zNodes = eval(zn);
		zTree = $.fn.zTree.init($("#tree"), setting, zNodes);
	});
	function zTreeOnClick(event, treeId, treeNode) {
		$("#parentId").val(treeNode.id);
		$("#parentName").val(treeNode.name);
		$("#parentDiv").hide();
	}
	var layer
	layui.use('layer', function () {
		layer = layui.layer;
	});
	//保存
	function submitHandler(){
		if(checkIsNull("deptName","请输入部门名称！")||checkIsNull("deptId","请输入部门编号！")){
			return;
		}
        $.ajax({
			url: '${basePath}system/dept/saveDept',
			data: $("#form1").serialize(),
			type: "POST",
			success: function(data){
				if (data.status == true) {
                    layer.alert(data.msg,function(index){
                        var index1 = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index1);
                        layer.close(index);
                    });
				}else{
					parent.layer.alert(data.msg);
				}
        	}
        });
    }
</script>
</body>
</html>
